package one.bugu.android.demon.ui.fragment;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.PointF;
import android.os.CountDownTimer;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.juefeng.android.framework.LKUtil;
import com.juefeng.android.framework.common.util.ToastUtils;
import com.juefeng.android.framework.view.annotation.LKContentView;
import com.juefeng.android.framework.view.annotation.LKInjectView;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import one.bugu.android.demon.R;
import one.bugu.android.demon.bean.FarmBGTBean;
import one.bugu.android.demon.bean.FarmBean;
import one.bugu.android.demon.bean.MedalBean;
import one.bugu.android.demon.bean.ProfitBean;
import one.bugu.android.demon.bean.snatch.WalletBean;
import one.bugu.android.demon.common.BaseHttpAsycResponceHandler;
import one.bugu.android.demon.common.MyBaseFragment;
import one.bugu.android.demon.constant.Constant;
import one.bugu.android.demon.constant.HttpConstant;
import one.bugu.android.demon.constant.MedalContant;
import one.bugu.android.demon.ui.activity.WarnMainActivity;
import one.bugu.android.demon.ui.activity.thirdparty.SpecialEventsActivity;
import one.bugu.android.demon.ui.activity.wallet.BGTActivity;
import one.bugu.android.demon.ui.activity.CalculationActivity;
import one.bugu.android.demon.ui.activity.WebActivity;
import one.bugu.android.demon.ui.dialog.DialogContent;
import one.bugu.android.demon.ui.dialog.DialogFirstIn;
import one.bugu.android.demon.ui.dialog.DialogMedal;
import one.bugu.android.demon.ui.dialog.DialogReward;
import one.bugu.android.demon.ui.dialog.DialogSnatch;
import one.bugu.android.demon.ui.dialog.DialogStrike;
import one.bugu.android.demon.ui.refresh.util.DensityUtil;
import one.bugu.android.demon.ui.widget.DropView;
import one.bugu.android.demon.util.DateUtils;
import one.bugu.android.demon.util.IntentUtils;
import one.bugu.android.demon.util.MedalUtils;
import one.bugu.android.demon.util.MyTextUtils;
import one.bugu.android.demon.util.NumScrollAnimUtils;
import one.bugu.android.demon.util.NumUtils;
import one.bugu.android.demon.util.OnViewClickListener;
import one.bugu.android.demon.util.ParamUtils;
import one.bugu.android.demon.util.PreferencesUtil;
import one.bugu.android.demon.util.RandomLocationUtil;
import one.bugu.android.demon.util.ShareImageUtils;
import one.bugu.android.demon.util.SoundPlayUtils;
import one.bugu.android.demon.util.StatusBarUtils;
import one.bugu.android.demon.util.VersionUtils;

/**
 * Created with IntelliJ IDEA.
 * User: LangK
 * Created Date 2018/9/20
 * Time: 15:38
 * Description: 农场界面
 */
@LKContentView(R.layout.fragment_bugu_farm)
public class FarmFragment extends MyBaseFragment {

    /**
     * 占位view
     */
    @LKInjectView(R.id.view_top)
    private View viewTop;

    @LKInjectView(R.id.fragment_farm)
    private FrameLayout frameLayout;

    @LKInjectView(R.id.iv_fram_earth)
    private ImageView ivFramEarth;

    /**
     * bgt数量
     */
    @LKInjectView(R.id.farm_bgt_num)
    private TextView bgtNumTextView;
    /**
     * 算力值
     */
    @LKInjectView(R.id.tv_suanli_num)
    private TextView tv_suanli_num;

    /**
     * 分红
     */
    @LKInjectView(R.id.iv_profit_des)
    private ImageView iv_profit_des;

    /**
     * 用户手机号
     */
    @LKInjectView(R.id.farm_userPhone)
    private TextView userPhone;
    /**
     * 用户头像
     */
    @LKInjectView(R.id.iv_user_avatar)
    private ImageView iv_user_avatar;

    /**
     * 农场手册
     */
    @LKInjectView(R.id.farmManual)
    private LinearLayout farmManual;

    /**
     * 我的bgt入口
     */
    @LKInjectView(R.id.myBGTInfo)
    private LinearLayout myBGTInfo;

    /**
     * 分红
     */
    @LKInjectView(R.id.ll_profit_layout)
    private LinearLayout ll_profit_layout;

    /**
     * 分红
     */
    @LKInjectView(R.id.tv_profit_num)
    private TextView tv_profit_num;
    /**
     * 邀请按钮
     */
    @LKInjectView(R.id.ll_invite_btn)
    private LinearLayout inviteBtn;

    /**
     * 算力值显示
     */
    @LKInjectView(R.id.farm_count)
    private LinearLayout getFramCount;
    /**
     * 算力圆圈
     */
    @LKInjectView(R.id.iv_suanli_icon)
    private ImageView iv_suanli_icon;

    /**
     * 夺宝按钮
     */
    @LKInjectView(R.id.ll_duobao_btn)
    private LinearLayout llDuoBaoBtn;

    /**
     * 游戏按钮
     */
    @LKInjectView(R.id.ll_game_btn)
    private LinearLayout llGameBtn;
    /**
     * 小说按钮
     */
    @LKInjectView(R.id.ll_book_btn)
    private LinearLayout llBookBtn;

    /**
     * 头衔
     */
    @LKInjectView(R.id.iv_farm_medal)
    private ImageView iv_farm_medal;

    /**
     * 暴击是否分享
     */
    private boolean isStrikeShare = false;

    private View dropStrikeView = null;

    private float x, y;

    private float viewSize = 0;

    private RandomLocationUtil randomLocationUtil;

    private Context mContext;

    private List<FarmBGTBean> listBGTs;

    private DecimalFormat format = new DecimalFormat("###.#####");

    private static final int MAX_NUM = 8;

    private String flag;
    /**
     * 排名
     */
    private int rankingNum;
    /**
     * 可领取的币数
     */
    private int drawBgtNum;

    /**
     * 分红数据刷新间隔
     */
    private static final int REFRUSH_INTERVAL = 5;
    /**
     * 分红定时器
     */
    private CountDownTimer countDownTimer;
    /**
     * 头衔分享
     */
    private boolean isMedalShare = false;

    /**
     * 分享等级
     */
    private int shareRowId = -1;

    /**
     * 分享后获取头衔等级
     */
    private int shareLevel = -1;
    private DialogMedal dialogMedal;

    private boolean pageHidden = false;

    @Override
    protected void initView() {
        super.initView();
        this.mContext = getActivity();
        //解决fragment嵌套出现状态栏异常问题
        StatusBarUtils.getInstance().setFragmentStatusBar(getContext(), viewTop);

        //初始化声音播放控件
        SoundPlayUtils.init(getContext());

        //设置地球旋转动画
        setEarthAnimation(ivFramEarth, 30 * 1000);

        //算力图标旋转动画
        setEarthAnimation(iv_suanli_icon, 8 * 1000);

    }

    @Override
    protected void initData() {
        super.initData();
        flag = PreferencesUtil.getInstance().getString(getContext(), Constant.FLAG);
        rankingNum = PreferencesUtil.getInstance().getInt(getContext(), Constant.RANKING_NUM);
        drawBgtNum = PreferencesUtil.getInstance().getInt(getContext(), Constant.DRAW_BGT_NUM);

        viewSize = DensityUtil.dp2px(60);
        bgtNumTextView.post(new Runnable() {
            @Override
            public void run() {
                x = bgtNumTextView.getX() + bgtNumTextView.getMeasuredWidth();
                y = bgtNumTextView.getY() + bgtNumTextView.getMeasuredHeight();
                y = y + DensityUtil.dp2px(50);
            }
        });
        frameLayout.post(new Runnable() {
            @Override
            public void run() {
                float framLayoutBY = frameLayout.getY() + frameLayout.getMeasuredHeight();
                float framLayoutRX = frameLayout.getX() + frameLayout.getMeasuredWidth() - viewSize;
                float framLayoutX = frameLayout.getX() + viewSize;
                float framLayoutY = framLayoutBY * 2 / 5;
                framLayoutBY = framLayoutBY * 4 / 5;
                randomLocationUtil = new RandomLocationUtil(framLayoutX, framLayoutY, framLayoutRX, framLayoutBY, viewSize / 2);
                //获取bgt数据
                getUserCanGetBgtNum();
            }
        });
        if (TextUtils.equals(flag, "1") && rankingNum > 0 && drawBgtNum > 0) {
            //新人报到, 显示弹窗
            showFirstInDialog();
        } else {
            signIn();
        }
    }


    @Override
    public void onResume() {
        super.onResume();
        //暴击分享后返回
        if (dropStrikeView != null) {
            playAudio();
            ((DropView) dropStrikeView).hide(x, y);
            //暴击已分享,重置状态
            isStrikeShare = true;
            //将保存的view置为null
            dropStrikeView = null;
        }
        //头衔分享
        if (isMedalShare && shareRowId != -1) {
            //请求领取接口
            getCalMedal(String.valueOf(shareRowId));
        }
        isMedalShare = false;
        //分红
        profitEth();
        //活动入口状态请求
        getSnatchStatus();
    }


    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        pageHidden = hidden;
        if (hidden && dialogMedal != null) {
            dialogMedal.dismiss();
        }
        if (!hidden) {
            getUserCanGetBgtNum();
            getSnatchStatus();
            return;
        }

    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 1001 && resultCode == Activity.RESULT_OK) {
            //算力值刷新
            String cal_num = data.getStringExtra("CAL_NUM");
            PreferencesUtil.getInstance().putInt(getContext(), Constant.CAL_NUM, Integer.parseInt(cal_num));
            tv_suanli_num.setText(cal_num);
        }
    }

    /**
     * BGT能量初始化
     */
    private void initFarm() {
        final float framLayoutY = frameLayout.getY() + viewSize;
        for (int i = 0; i < frameLayout.getChildCount(); i++) {
            randomLocationUtil.remove(i);
            frameLayout.getChildAt(i).clearAnimation();
            frameLayout.getChildAt(i).setVisibility(View.GONE);
        }
        frameLayout.removeAllViews();
        randomLocationUtil.remove(-1);
        if (listBGTs == null || listBGTs.size() == 0) {
            int defViewSize = DensityUtil.dp2px(120);
            DropView dropView = new DropView(mContext, DropView.TIME_COUNT);
            PointF pointF = randomLocationUtil.generationNewPoint(-1);
            FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(defViewSize, defViewSize);
            layoutParams.setMargins((int) (pointF.x - defViewSize / 2), (int) ((pointF.y - framLayoutY) - defViewSize / 2), 0, 0);
            frameLayout.addView(dropView, layoutParams);
            dropView.startAnimation();
            //定时刷新
            dropView.setOnRefrushListener(new DropView.OnRefrushListener() {
                @Override
                public void refrushData() {
                    getUserCanGetBgtNum();
                }
            });
            return;
        }
        final List<FarmBGTBean> tempList = new ArrayList<>();
        if (listBGTs.size() > MAX_NUM) {
            tempList.addAll(listBGTs.subList(0, MAX_NUM));
        } else {
            tempList.addAll(listBGTs);
        }
        for (int i = 0; i < tempList.size(); i++) {
            final FarmBGTBean farmBGTBean = tempList.get(i);
            PointF pointF = randomLocationUtil.generationNewPoint(i);
            if (pointF == null) {
                return;
            }
            final DropView dropView = new DropView(mContext, format.format(farmBGTBean.getNum()));
            dropView.setTag(i);
            FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams((int) viewSize, (int) viewSize);
            layoutParams.setMargins((int) (pointF.x - viewSize / 2), (int) ((pointF.y - framLayoutY) - viewSize / 2), 0, 0);
            frameLayout.addView(dropView, i, layoutParams);
            dropView.setOnClickListener(new OnViewClickListener() {
                @Override
                public void singleClick(View v) {
                    if (farmBGTBean.getDoubleNum() > 0) {
                        dropStrikeView = v;
                        showStrikeDialog(farmBGTBean.getDoubleNum());
                    } else {
                        //带暴击bgt球, 直接领取
                        playAudio();
                        ((DropView) v).hide(x, y);
                    }
                }
            });
            dropView.setOnHideListener(new DropView.OnHideListener() {
                @SuppressLint("SetTextI18n")
                @Override
                public void removed(View view) {
                    int tag = (Integer) view.getTag();
                    bgtNumTextView.setText(format.format(Double.parseDouble(bgtNumTextView.getText().toString()) + tempList.get(tag).getNum()) + "");
                    listBGTs.remove(tempList.get(tag));
                    randomLocationUtil.remove(tag);
                    frameLayout.removeView(view);
                    pullBGT(tempList.get(tag).getTimestamp(), tempList.get(tag).getNum());
                    if (randomLocationUtil.isEmpty()) {
                        frameLayout.removeAllViews();
                        initFarm();
                    }
                }
            });
            dropView.startAnimation();
        }
    }

    @SuppressLint("ClickableViewAccessibility")
    @Override
    protected void initEvent() {
        super.initEvent();
        //跳转我的bgt页面
        myBGTInfo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //IntentUtils.startAty(getActivity(), BGTActivity.class);
                Intent intent = new Intent(getActivity(), BGTActivity.class);
                WalletBean walletBean = new WalletBean();
                walletBean.setBalance(Double.parseDouble(bgtNumTextView.getText().toString()));
                intent.putExtra(Constant.NUMBER, walletBean);
                intent.putExtra(Constant.PAGETITLE, "我的BGT");
                startActivity(intent);
            }
        });

        //分红点击
        ll_profit_layout.setOnClickListener(new OnViewClickListener() {
            @Override
            protected void singleClick(View view) {
                //显示弹窗
                showProfitDialog();
            }
        });
        //分红弹窗
        iv_profit_des.setOnClickListener(new OnViewClickListener() {
            @Override
            protected void singleClick(View view) {
                //显示弹窗
                showProfitDialog();
            }
        });
        //跳转农场手册页面
        farmManual.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                List<ParamUtils.NameValue> parList = ParamUtils.build().put(WebActivity.TITLE, "农场手册").put(WebActivity.URL, HttpConstant.FRAMMANUAL_URL).create();
                IntentUtils.startAty(getActivity(), WebActivity.class, parList);
            }
        });

        //邀请按钮点击事件
        inviteBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                List<ParamUtils.NameValue> parList = ParamUtils.build().put(WebActivity.TITLE, "邀请好友").put(WebActivity.URL, HttpConstant.INVID_URL).create();
                IntentUtils.startAty(getActivity(), WebActivity.class, parList);
            }
        });

        //算力值跳转
        getFramCount.setOnClickListener(new OnViewClickListener() {
            @Override
            protected void singleClick(View view) {
                Intent intent = new Intent(getActivity(), CalculationActivity.class);
                intent.putExtra(Constant.CALCULATION, tv_suanli_num.getText().toString());
                startActivityForResult(intent, 1001);
            }
        });
        //夺宝按钮
        llDuoBaoBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                IntentUtils.startAty(getContext(), SnatchActivity.class);
                IntentUtils.startAty(getContext(), WarnMainActivity.class, Constant.ID, 0);
            }
        });
        //游戏按钮
        llGameBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                List<ParamUtils.NameValue> values = ParamUtils.build().put(SpecialEventsActivity.PAGE_TITLE, SpecialEventsActivity.GAME_TITLE).create();
                IntentUtils.startAty(getContext(), SpecialEventsActivity.class, values);
            }
        });
        //小说按钮
        llBookBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                List<ParamUtils.NameValue> values = ParamUtils.build().put(SpecialEventsActivity.PAGE_TITLE, SpecialEventsActivity.BOOK_TITLE).create();
                IntentUtils.startAty(getContext(), SpecialEventsActivity.class, values);
            }
        });
    }

    /**
     * BGT领取
     */
    private void pullBGT(long time, double num) {
        String token = PreferencesUtil.getInstance().getString(getActivity(), Constant.TOKEN);
        Map<String, String> map = new HashMap<>();
        map.put("token", token);
        map.put("bgtNum", num + "");
        map.put("timestamp", time + "");
        map.put("shareFlag", isStrikeShare ? "1" : "0");
        //重置分享状态
        isStrikeShare = false;
        LKUtil.getHttpManager().postBody(HttpConstant.GET_FARM_BGT_URL, map, bgtHandler);
    }

    /**
     * 获取用户可领取BGT
     */
    public void getUserCanGetBgtNum() {
        String token = PreferencesUtil.getInstance().getString(getActivity(), Constant.TOKEN);
        Map<String, String> map = new HashMap<>();
        map.put("token", token);
        LKUtil.getHttpManager().postBody(HttpConstant.GET_FARM_URL, map, handler);
    }

    /**
     * 签到
     */
    public void signIn() {
        String token = PreferencesUtil.getInstance().getString(getActivity(), Constant.TOKEN);
        String verName = VersionUtils.getVerName(getContext());
        if (verName == null) {
            verName = "";
        }
        verName = verName.replace(".", "");
        Map<String, String> map = new HashMap<>();
        map.put("token", token);
        map.put("sourceId", "50");
        map.put("appId", "3");
        map.put("verCode", verName);
        LKUtil.getHttpManager().postBody(HttpConstant.GET_SIGN_IN_URL, map, signHandler);
    }

    /**
     * 控制显示夺宝活动入口
     */
    private void getSnatchStatus() {
        String token = PreferencesUtil.getInstance().getString(getActivity(), Constant.TOKEN);
        Map<String, String> map = new HashMap<>();
        map.put("token", token);
        LKUtil.getHttpManager().postBody(HttpConstant.SNATCH_VISIABLE_STATUS, map, snatchHandler);
    }

    /**
     * 分红
     */
    private void profitEth() {
        String token = PreferencesUtil.getInstance().getString(getActivity(), Constant.TOKEN);
        Map<String, String> map = new HashMap<>();
        map.put("token", token);
        LKUtil.getHttpManager().postBody(HttpConstant.PROFIT_ETH, map, prifitHandler);
    }

    /**
     * 算力头衔领取
     */
    private void getCalMedal(String titleId) {
        String token = PreferencesUtil.getInstance().getString(getActivity(), Constant.TOKEN);
        Map<String, String> map = new HashMap<>();
        map.put("token", token);
        map.put("titleId", titleId);
        LKUtil.getHttpManager().post(HttpConstant.GET_CAL_MEDAL, map, getHandler);
    }

    /**
     * 领取BGT的网络请求
     */
    @SuppressLint("HandlerLeak")
    public BaseHttpAsycResponceHandler<Object> snatchHandler = new BaseHttpAsycResponceHandler<Object>() {
        @Override
        public void onSuccess(Object data) {
            super.onSuccess(data);
            //显示夺宝弹窗
            showSnatchDialog();
            //控制夺宝入口
            llDuoBaoBtn.setVisibility(View.VISIBLE);
        }

        @Override
        public void onFailed(int code, String message) {
            super.onFailed(code, message);
            //控制夺宝入口
            llDuoBaoBtn.setVisibility(View.GONE);
        }

        @Override
        public void onError() {
            super.onError();
        }
    };

    /**
     * 领取BGT的网络请求
     */
    @SuppressLint("HandlerLeak")
    public BaseHttpAsycResponceHandler<String> bgtHandler = new BaseHttpAsycResponceHandler<String>() {
        @Override
        public void onSuccess(String data) {
            super.onSuccess(data);
        }

        @Override
        public void onFailed(int code, String message) {
            super.onFailed(code, message);
        }

        @Override
        public void onError() {
            super.onError();
        }
    };

    /**
     * 获取农场首页的网络请求
     */
    @SuppressLint("HandlerLeak")
    public BaseHttpAsycResponceHandler<FarmBean> handler = new BaseHttpAsycResponceHandler<FarmBean>() {
        @SuppressLint("SetTextI18n")
        @Override
        public void onSuccess(FarmBean data) {
            super.onSuccess(data);
            if (data == null) {
                return;
            }
            FarmFragment.this.listBGTs = data.getGrantBgt();
            //BGT数量
            bgtNumTextView.setText(format.format(data.getBgt()) + "");
            //用户昵称
            boolean flag = data.getNickname() != null && !TextUtils.isEmpty(data.getNickname());
            String name = flag ? data.getNickname() : "";
            userPhone.setText(TextUtils.isEmpty(name) ? data.getUserAccount() : name);
            //保存昵称
            PreferencesUtil.getInstance().putString(getContext(), Constant.USER_NAMR, name);
            //保存头像
            PreferencesUtil.getInstance().putString(getContext(), Constant.USER_AVATAR, data.getPhoto());
            //用户头像
            LKUtil.getImageLoader().loadRoundImage(data.getPhoto(),
                    iv_user_avatar,
                    R.mipmap.nongchang_touxiang);
            //算力值
            tv_suanli_num.setText((int) (data.getPower()) + "");
            PreferencesUtil.getInstance().putInt(getContext(), Constant.CAL_NUM, (int) (data.getPower()));

            //算力头衔等级
            List<MedalBean> powerTitle = data.getPowerTitle();
            List<Integer> getPower = data.getGetPower();
            double power = data.getPower();
            //数据处理, 设置头衔以及是否弹框
            for (int i = 0; i < powerTitle.size(); i++) {
                //判断显示领取弹框
                if (power >= powerTitle.get(i).getMinNum() && power < powerTitle.get(i).getMaxNum()) {
                    if (getPower == null || !getPower.contains(powerTitle.get(i).getRowId())) {
                        //当期最高算力头衔未领取
                        shareRowId = powerTitle.get(i).getRowId();
                        shareLevel = i;
                        //第一次弹出框后未领取不再弹出
                        boolean showBgtMedalDialog = MedalUtils.getInstance().isShowBgtMedalDialog(getContext(), i, false);
                        if (showBgtMedalDialog) {
                            showBgtMedalDialog(MedalContant.farmMedalImage[i], i);
                        }
                        //显示最接近当前头衔ID的头衔名称
                        if (getPower != null) {
                            int nearByRowId = MedalUtils.getInstance().getNearByRowId(getPower, powerTitle.get(i).getRowId());
                            int medalevel = MedalUtils.getInstance().getMedalevel(nearByRowId, powerTitle);
                            iv_farm_medal.setImageResource(MedalContant.farmMedalImage[medalevel]);
                        } else {
                            iv_farm_medal.setImageResource(MedalContant.farmMedalImage[0]);
                        }
                    } else {
                        iv_farm_medal.setImageResource(MedalContant.farmMedalImage[i]);
                    }
                }
            }
            initFarm();
        }

        @Override
        public void onFailed(int code, String message) {
            super.onFailed(code, message);

        }

        @Override
        public void onError() {
            super.onError();
        }
    };

    /**
     * 获取算力信息的网络请求
     */
    @SuppressLint("HandlerLeak")
    public BaseHttpAsycResponceHandler<String> getHandler = new BaseHttpAsycResponceHandler<String>(false) {
        @Override
        public void onSuccess(String data) {
            super.onSuccess(data);
            ToastUtils.custom("领取成功");
            if (shareLevel != -1) {
                iv_farm_medal.setImageResource(MedalContant.farmMedalImage[shareLevel]);
            }
            //状态重置
            shareLevel = -1;
            shareRowId = -1;
        }

        @Override
        public void onFailed(int code, String message) {
            super.onFailed(code, message);

        }

        @Override
        public void onError() {
            super.onError();

        }
    };

    /**
     * 获取农场首页的网络请求
     */
    @SuppressLint("HandlerLeak")
    public BaseHttpAsycResponceHandler<String> signHandler = new BaseHttpAsycResponceHandler<String>() {
        @Override
        public void onSuccess(String data) {
            super.onSuccess(data);
            //显示签到弹窗
            dialogShowfile(data);
        }

        @Override
        public void onFailed(int code, String message) {
            super.onFailed(code, message);
        }

        @Override
        public void onError() {
            super.onError();
        }
    };

    /**
     * 分红
     */
    @SuppressLint("HandlerLeak")
    public BaseHttpAsycResponceHandler<ProfitBean> prifitHandler = new BaseHttpAsycResponceHandler<ProfitBean>() {
        @Override
        public void onSuccess(ProfitBean data) {
            super.onSuccess(data);
            //分红
            setProfitNum(data.getLastAllot(), data.getNum(), data.getSleepTime(), data.getLastDate());
        }

        @Override
        public void onFailed(int code, String message) {
            super.onFailed(code, message);
        }

        @Override
        public void onError() {
            super.onError();
        }
    };

    /**
     * 播放音频
     */
    private void playAudio() {
        SoundPlayUtils.play();
    }

    /**
     * 签到弹窗
     *
     * @param s 弹窗显示问数据
     */
    private void dialogShowfile(final String s) {
        try {
            String[] strings = s.split("，");
            DialogReward dialogReward = new DialogReward(getActivity(), "获得奖励", strings[0], strings[1], false, false);
            dialogReward.show();
        } catch (Exception e) {
            Log.e("qiandao", e.getMessage());
        }
    }

    /**
     * 首次进入弹窗
     */
    private void showFirstInDialog() {
        DialogFirstIn dialogFirstIn = new DialogFirstIn(getContext(), R.style.DialogBottom);
        dialogFirstIn.setData(rankingNum, drawBgtNum);
        dialogFirstIn.setOnDismissListener(new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
                PreferencesUtil.getInstance().putInt(getContext(), Constant.RANKING_NUM, 0);
                PreferencesUtil.getInstance().putInt(getContext(), Constant.DRAW_BGT_NUM, 0);
                signIn();
            }
        });
        dialogFirstIn.show();
    }

    /**
     * 显示夺宝广告弹窗
     */
    private void showSnatchDialog() {
        boolean hasShow = PreferencesUtil.getInstance().getBoolean(getContext(), Constant.HAS_SHOEW_SNATCH_DIALOG);
        if (!hasShow) {
            DialogSnatch snatchDialog = new DialogSnatch(getContext(), R.style.DialogBottom);
            snatchDialog.show();
            PreferencesUtil.getInstance().putBoolean(getContext(), Constant.HAS_SHOEW_SNATCH_DIALOG, true);
        }
    }

    /**
     * 分红说明弹窗
     */
    private void showProfitDialog() {
        DialogContent dialog = new DialogContent(mContext, R.style.DialogBottom, 0.8);
        View view = View.inflate(mContext, R.layout.dialog_profit_role_content, null);
        TextView tv_profit_rule = view.findViewById(R.id.tv_profit_rule);
        String content = mContext.getResources().getString(R.string.str_profit_rule_2);
        MyTextUtils.getInstance().setParagraphSpacing(mContext, tv_profit_rule, content, 20, 8);
        dialog.setViewAndBackground(view, R.drawable.shape_dialog_content_bg);
        if (!dialog.isShowing()) {
            dialog.show();
        }
    }

    /**
     * 显示暴击弹窗
     */
    private void showStrikeDialog(double value) {
        final DialogStrike strikeDialog = new DialogStrike(mContext, R.style.DialogBottom);
        strikeDialog.setStriValue(value);
        strikeDialog.setOnShareBtnClick(new DialogStrike.OnShareBtnClick() {
            @Override
            public void onShareBtnClickListener() {
                //分享
                ShareImageUtils.getInstance().compShareImage(getActivity(), strikeDialog);
                strikeDialog.dismiss();
            }

            @Override
            public void onShareCancleListener() {
                //取消
                strikeDialog.dismiss();
                isStrikeShare = false;
                playAudio();
                ((DropView) dropStrikeView).hide(x, y);
                //将保存的view置为null
                dropStrikeView = null;
            }
        });
        if (!strikeDialog.isShowing()) {
            strikeDialog.show();
        }
    }

    /**
     * 显示算力头衔弹框
     */
    private void showBgtMedalDialog(int levImage, final int level) {
        if (dialogMedal == null) {
            dialogMedal = new DialogMedal(getContext(), R.style.DialogCenter);
        }
        dialogMedal.setDialogBg(R.mipmap.icon_suanli_dialog_bg);
        dialogMedal.setImageRes(levImage);
        dialogMedal.setLevelTitle("");
        dialogMedal.setStatus(false);
        dialogMedal.setOnGetBtnClick(new DialogMedal.OnGetBtnClick() {
            @Override
            public void onGetBtnClickListener() {
                isMedalShare = true;
                ShareImageUtils.getInstance().compShareImage(getActivity(), dialogMedal);
            }
        });
        dialogMedal.setOnDismissListener(new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
                MedalUtils.getInstance().saveMedalLevStatus(getContext(), level, false);
            }
        });
        if (!dialogMedal.isShowing() && !pageHidden) {
            dialogMedal.show();
        }
    }

    /**
     * 地球图片旋转动画
     *
     * @param view
     */
    private void setEarthAnimation(View view, long duration) {
        final RotateAnimation anim = new RotateAnimation(0f, 360f,
                Animation.RELATIVE_TO_SELF, 0.5f,
                Animation.RELATIVE_TO_SELF, 0.5f);
        // 设置保持动画最后的状态
        anim.setFillAfter(true);
        // 设置动画时间
        anim.setDuration(duration);
        anim.setRepeatCount(Animation.INFINITE);
        // 设置插值器
        anim.setInterpolator(new LinearInterpolator());
        view.startAnimation(anim);
    }

    /**
     * 设置ETH分红数据动画效果
     */
    private void setProfitNum(double afterNum, final double addNum, int sleepTime, String lastDate) {
        int afterMillis = DateUtils.getAfterMillis();
        //已经刷新次数
        double count = afterMillis / REFRUSH_INTERVAL;
        //当前时间分红总数
        double totalNum = addNum * count + afterNum;
        tv_profit_num.setText(NumUtils.NumberFormat(totalNum, 12));
        //初次进入时增加值为全部数值, 初始值为0.0
        NumScrollAnimUtils.startAnim(tv_profit_num, totalNum, 0.0, 1000);
        boolean yesterday = DateUtils.IsYesterday(lastDate);
        if (!yesterday) {
            return;
        }
        //定时任务增加数值
        startTime(addNum, sleepTime);
    }

    /**
     * 开始倒计时
     *
     * @param addNum
     * @param sleepTime
     */
    private void startTime(final double addNum, final int sleepTime) {
        if (countDownTimer != null) {
            countDownTimer.cancel();
        }
        countDownTimer = new CountDownTimer(sleepTime * 1000, 1000) {
            @Override
            public void onTick(long millisUntilFinished) {

            }

            @Override
            public void onFinish() {
                String profitNum = tv_profit_num.getText().toString().trim();
                double profitNumF = Double.parseDouble(profitNum);
                NumScrollAnimUtils.startAnim(tv_profit_num, addNum, profitNumF, 800);
                //继续开始
                startTime(addNum, sleepTime);
            }
        }.start();
    }
}
